#include "stdafx.h"

int main(int argc, char* argv[])
{
	using namespace libnt;
	arg_parse arg;
	MyShell shell;
	argument* parg = NULL;
	char* pszSavePath = NULL;
	int ret = -1;
	
	bool succed = arg.parse(argc,argv,APP_OPTION);
	if (!succed)
	{
		shell.ShowHelp();
		return -1;
	}
    parg=arg.getarg();
	if (parg) 
	{
		shell.SetServer(parg->valp);
	}
	
	bool bHasGetFlag = false;
	while ((parg=arg.getopt())!=NULL)
	{
		switch (parg->flag)
		{
		case 'o':
			pszSavePath = parg->valp;break;
		case 'g':
			bHasGetFlag = true;break;
		case 'v':
			shell.ShowVersion();return 0;
		default:
			break;
		}
	}

	if (pszSavePath!=NULL && !bHasGetFlag) 
	{
		printf("usage:%s <ipaddress> -g <param1> -o <param2>\r\n",APP_NAME);
		return -1;
	}

	while ((parg=arg.getopt())!=NULL)
	{
		switch (parg->flag)
		{
			case 'g':
				ret = shell.ProcCmdGet(parg->valp,pszSavePath);break;
			case 'p':
				ret = shell.ProcCmdPut(parg->valp);break;
			default:
				break;
		}
		//debug("flag:'%c',valp:%s\n",parg->flag,parg->valp);
	}
	return ret;
}

